package com.example.makerspace.dao;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.makerspace.domain.ExpertOutcomeDO;
import com.example.makerspace.domain.ExpertTaskDO;
import com.example.makerspace.dto.Pagination;
import com.example.makerspace.mapper.ExpertTaskMapper;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.List;

@Component
public class ExpertTaskDAO extends  BaseDAO<ExpertTaskDO> {
    @Resource
    private ExpertTaskMapper expertTaskMapper;

    @PostConstruct
    public void init(){
        this.mapper = expertTaskMapper;
    }

    public List<ExpertTaskDO> selectByUserName(String username) {
        QueryWrapper<ExpertTaskDO> wrapper = new QueryWrapper<>();
        wrapper.eq("username",username);
        return mapper.selectList(wrapper);
    }

    public IPage<ExpertTaskDO> selectByPage(Pagination pagination) {
        QueryWrapper<ExpertTaskDO> wrapper = new QueryWrapper<>();
        wrapper.orderByDesc("create_time");
        return  mapper.selectPage(new Page<>(pagination.getPageNum(),pagination.getSize()),wrapper);
    }

    public IPage<ExpertTaskDO> selectByPageAndName(Pagination pagination, String name) {
        QueryWrapper<ExpertTaskDO> wrapper = new QueryWrapper<>();
        wrapper.like("username",name).or().like("name",name).or().like("title",name);;
        wrapper.orderByDesc("create_time");
        return  mapper.selectPage(new Page<>(pagination.getPageNum(),pagination.getSize()),wrapper);
    }

    public IPage<ExpertTaskDO> selectByPageEqUserName(Pagination pagination, String username) {
        QueryWrapper<ExpertTaskDO> wrapper = new QueryWrapper<>();
        wrapper.eq("username",username);
        return  mapper.selectPage(new Page<>(pagination.getPageNum(),pagination.getSize()),wrapper);
    }

    public ExpertTaskDO selectByPageAndTaskId(Integer taskId) {
            QueryWrapper<ExpertTaskDO> wrapper = new QueryWrapper<>();
            wrapper.eq("id",taskId);
            return mapper.selectOne(wrapper);
    }

    public List<ExpertTaskDO> selectByPageInTaskId(List<Integer> taskId) {
        QueryWrapper<ExpertTaskDO> wrapper = new QueryWrapper<>();
        wrapper.in("id",taskId);
        return  mapper.selectList(wrapper);
    }
}
